<?php
/**
 * Created by PhpStorm.
 * User: huihu
 * Date: 2016/5/11
 * Time: 17:57
 */

namespace app\app\behavior;
use app\app\error;

class Response
{
    public function return_data(&$data){

        // 异常处理
        $rs = array();
        if (!is_int($data)){

            $rs = array(
                'data'      =>  $data?$data:array(),
                'success'   =>  1,
                'error'     =>  0,
            );
        }else{

            if (array_key_exists($data,error::$error)){
                $rs = array(
                    'success'   =>  0,
                    'error'     =>  $data,
                    'error_desc'    =>  error::$error[$data],
                );
            }else{
                $rs = array(
                    'success'   =>  0,
                    'error'     =>  -1,
                    'error_desc'    =>  '未知错误',
                );
            }
        }
//        $data = json_encode($rs);
        return $rs;
    }



}